from google.appengine.ext import db

class Golfers( db.Model ):
	pass
class Outings ( db.Model ):
	pass

class Course( db.Model ):
	name = db.StringProperty()
	location = db.GeoPtProperty()
	def get_absolute_url(self):
		return '/course/%s/' % self.key()
	def sum_holes(self):
		"""sum of holes' pars"""
		return sum([h.par for h in self.holes])
	
class Hole( db.Model ):
	number = db.IntegerProperty()
	name = db.StringProperty()
	par = db.IntegerProperty()
	course = db.ReferenceProperty( Course , collection_name='holes')
	
class Golfer( db.Model ):
	name = db.StringProperty()
	short_name = db.StringProperty()
	outing_list = db.ReferenceProperty( Outings )
	def get_absolute_url(self):
		return '/golfer/%s/' % self.key()
	def get_handicap(self):
		return 0

class Outing( db.Model ):
	tee_time = db.DateTimeProperty()
	golfer_list = db.ReferenceProperty( Golfers )
	course = db.ReferenceProperty( Course )
	
class Round( db.Model ):	
	golfer = db.ReferenceProperty( Golfer )
	outing = db.ReferenceProperty( Outing )

class Score( db. Model ):
	round = db.ReferenceProperty( Round )
	score = db.IntegerProperty()